<template>
    <el-form ref="form" :model="detail" :rules="rules" label-width="80px">

      <el-form-item label="银行卡号" prop="bankCard" >
        <el-input v-model="detail.bankCard" maxlength="50" />
      </el-form-item>

  
      <el-form-item>
        <el-button type="primary" size="mini" @click="submit">保存</el-button>
        <el-button type="danger" size="mini" @click="close">关闭</el-button>
      </el-form-item>
    </el-form>
  </template>
    
  <script>

  import {getUserDetail,updateUserDetailProfile} from "@/api/credit/creUser";


  
  export default {
    name: "",
    components: { updateUserDetailProfile, getUserDetail },
    props: {
      user: {
        type: Object
      },
      percentage:{
      type: Number
    }
    },
    data() {
      return {
        detail: [],
    
        // 表单校验
        rules: {
          bankCard:[            
            { required: true, message: "银行卡号不能为空", trigger: "blur" },
            {
            pattern: /^([1-9]{1})(\d{14}|\d{15}|\d{16}|\d{17})$/,
            message: "银行卡号不符合规范，应为15~18位纯数字",
            trigger: "blur"
          }
            ]
        }
      };
    },
    methods: {
    findUserDetail() {
      getUserDetail(this.user.userId).then(res => {
        this.detail = res.data
        this.percentageInitialization()
      }).catch()
    },
      submit() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            updateUserDetailProfile(this.detail).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.increase()
            });
          }
        });
      },
      close() {
        this.$tab.closePage();
      },
     
      increase() {
        console.log(this.percentage);
        if (this.percentage > 100) {
          this.percentage = 100;
        }
        this.$emit('increase',this.percentage);
      },
      decrease() {
        this.percentage -= 10;
        if (this.percentage < 0) {
          this.percentage = 0;
        }
      },
      percentageInitialization() {
      this.percentage = 0
      if (this.user.phonenumber) {
        this.percentage += 5
      }
      if (this.user.email) {
        this.percentage += 5
      }
      if (this.user.sex != "2") {
        this.percentage += 5
      }
      if (this.detail.realName) {
        this.percentage += 5
      }
      if (this.detail.identityCard) {
        this.percentage += 5
      }
      if (this.detail.educationLevel) {
        this.percentage += 5
      }
      if (this.detail.bankCard) {
        this.percentage += 5
      }
      if (this.detail.occupation) {
        this.percentage += 5
      }
      if (this.detail.monthIncome) {
        this.percentage += 5
      }
      if (this.detail.address) {
        this.percentage += 5
      }
      if (this.detail.houseCertificate) {
        this.percentage += 5
      }
      if (this.detail.emergencyPhone) {
        this.percentage += 5
      }
      if (this.detail.password) {
        this.percentage += 5
      }
      if (this.user.userName) {
        this.percentage += 5
      }
    }

  },
  watch: {
    user: function (newData, oldData) {
      console.log(oldData, newData);
      this.findUserDetail()
    },
    percentage:function(newData,oldData){
      console.log(oldData, newData);
      this.percentage=newData
    }
  }
  };
  </script>
    